#include <stdio.h>

#define __NON_INSTRUMENT_FUNCTION__ __attribute__((__no_instrument_function__))
#define CALLTRACE_OFF        __NON_INSTRUMENT_FUNCTION__
#define TRACE_FILENAME "test.out"
FILE* fd;

void CALLTRACE_OFF callgraph_exit()
{
	fclose(fd);
}

void CALLTRACE_OFF callgraph_init()
{
	fd = NULL;

	fd = fopen(TRACE_FILENAME,"w+");

	if (fd == NULL) {
		perror("callgraph_init:Error opening file\n");
	} else {
		atexit(callgraph_exit);
	}
	
}
void CALLTRACE_OFF __cyg_profile_func_enter (void *this_fn,
	void *call_site) 
{
	static int first=0;

	if (!first) {
		callgraph_init();
		first=1;
	}
	fprintf(fd,"++ %x\n",this_fn);
	

}
void CALLTRACE_OFF __cyg_profile_func_exit  (void *this_fn,
	void *call_site)
{
	fprintf(fd,"-- %x\n",this_fn);

}


#ifdef TEST
void callFoo()
{
}
int main()
{
	callFoo();
	return 0;
}
#endif
